/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Backing;

import BL.AlmacenamientoBL;
import BL.BusquedaBL;
import java.util.List;
import javax.faces.component.html.HtmlForm;
import javax.faces.component.html.HtmlInputText;
import javax.faces.component.html.HtmlOutputText;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;


/**
 *
 * @author externo.drisco
 */
public class indexBean {

    private HtmlForm findex;
    private HtmlInputText txtConsulta;
    private HtmlOutputText txtMensaje;

    /** Creates a new instance of indexBean */
    public indexBean() {
        System.out.println("constructor index");
    }

    public HtmlForm getFindex() {
        return findex;
    }

    public void setFindex(HtmlForm findex) {
        this.findex = findex;
    }

    public HtmlInputText getTxtConsulta() {
        return txtConsulta;
    }

    public void setTxtConsulta(HtmlInputText txtConsulta) {
        this.txtConsulta = txtConsulta;
    }

    public HtmlOutputText getTxtMensaje() {
        return txtMensaje;
    }

    public void setTxtMensaje(HtmlOutputText txtMensaje) {
        this.txtMensaje = txtMensaje;
    }

    public Object buscar(){


        if(txtConsulta.getValue().equals("")){
            return null;
        }else{
        System.out.println(txtConsulta.getValue());

        BusquedaBL objBusBl = new BusquedaBL();
        List<String> arrPalabras = objBusBl.obtenerPalabrasClave((String)txtConsulta.getValue());

        guardarSesion("arrPalabras",arrPalabras);

        return "resBus01";}
    }

    public void guardarSesion(String palabraClave,Object obj){

        FacesContext context = javax.faces.context.FacesContext.getCurrentInstance();
        HttpSession session = (HttpSession) context.getExternalContext().getSession(false);
        session.setAttribute(palabraClave,obj);
    }

    public Object almacenarCrawler(){

        AlmacenamientoBL objAlmacBL = new AlmacenamientoBL();

        objAlmacBL.almacenarPaginasCrawler();

        txtMensaje.setValue("Termino de almacenar los valores traidos del Crawler");

        return false;
    }
}
